var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("CommonHelper"),
    s = e("Game"),
    l = e("ObjectPool"),
    c = e("RoleSoldierInfo"),
    d = e("AD"),
    h = e("UIManager"),
    _ = cc._decorator,
    u = _.ccclass,
    p = _.property,
    m = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.loading_bar = null),
                (t.loading_label = null),
                (t.player_node_view = null),
                (t.tip_label = null),
                (t.uiManager = null),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.initView = function () {
                d.default.getInstance().hideBanner(),
                    (this.uiManager = cc.find("UIManager").getComponent(h.default)),
                    this.uiManager.showCoinAndZs(!1);
                var e = a.GlobalParams.GameHeroIndex.concat([]);
                e.splice(e.indexOf(a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].role_id), 1);
                for (var t = 0; t < 2; t++) {
                    var o = r.default.getRandomInt(0, e.length - 1),
                        n = {hero_id: e[o], is_video: !0};
                    a.GlobalParams.ReviveHeroInfo.push(n), e.splice(o, 1);
                }
                (a.GlobalParams.start_time = new Date().getTime()),
                    this.showLoadInfo(),
                    l.default.getInstance().init(),
                    this.changeScene(),
                    this.showTipInfo();
            }),
            (t.prototype.changeScene = function () {
                return __awaiter(this, void 0, void 0, function () {
                    var e = this;
                    return __generator(this, function (t) {
                        switch (t.label) {
                            case 0:
                                return (
                                    this.setProgress(),
                                    this.setLabel("加载英雄资源。。。"),
                                    [4, i.default.getInstance().loadFightPrefabs("roles_prefabs")]
                                );
                            case 1:
                                return (
                                    t.sent(),
                                    this.setProgessOver(),
                                    this.setLabel("加载音效资源。。。"),
                                    [4, i.default.getInstance().loadFightAudio("sound/fight_sound")]
                                );
                            case 2:
                                return (
                                    t.sent(),
                                    this.setProgessOver(),
                                    this.setLabel("加载游戏场景资源。。。"),
                                    cc.director.preloadScene("Fight", null, function (t) {
                                        t
                                            ? console.error("======场景加载错误========", t)
                                            : (e.unscheduleAllCallbacks(),
                                              cc
                                                  .tween(e.loading_bar)
                                                  .to(0.2, {width: 1280})
                                                  .call(function () {
                                                      cc.director.loadScene("Fight");
                                                  })
                                                  .start());
                                    }),
                                    [2]
                                );
                        }
                    });
                });
            }),
            (t.prototype.setLabel = function (e) {
                this.loading_label.string = e;
            }),
            (t.prototype.setProgress = function () {
                var e = this;
                this.unscheduleAllCallbacks(),
                    (this.loading_bar.width = 0),
                    this.schedule(function () {
                        cc.tween(e.loading_bar)
                            .by(0.2, {width: 10})
                            .call(function () {
                                e.loading_bar.width >= 1200 && e.unscheduleAllCallbacks();
                            })
                            .start();
                    }, 0.2);
            }),
            (t.prototype.setProgessOver = function () {
                var e = this;
                this.unscheduleAllCallbacks(),
                    cc
                        .tween(this.loading_bar)
                        .to(0.2, {width: 1280})
                        .call(function () {
                            e.setProgress();
                        })
                        .start();
            }),
            (t.prototype.showLoadInfo = function () {
                for (var e = 0; e < 6; e++) {
                    var t = c.default.Role_info[a.GlobalParams.MatchGamePlayer[e].role_id],
                        o = this.player_node_view.children[e];
                    (o.children[0].getComponent(cc.Sprite).spriteFrame = i.default
                        .getInstance()
                        .getHeroCardFrame(t.C_ID)),
                        (o.getChildByName("hero_name").getComponent(cc.Label).string = t.C_Name),
                        (o.getChildByName("player_name").getComponent(cc.Label).string =
                            a.GlobalParams.MatchGamePlayer[e].name);
                }
            }),
            (t.prototype.showTipInfo = function () {
                var e = this;
                (this.tip_label.string =
                    s.default.login_tip_list[r.default.getRandomInt(0, s.default.login_tip_list.length - 1)]),
                    cc
                        .tween(this.tip_label)
                        .delay(3)
                        .call(function () {
                            e.showTipInfo();
                        })
                        .start();
            }),
            __decorate([p(cc.Node)], t.prototype, "loading_bar", void 0),
            __decorate([p(cc.Label)], t.prototype, "loading_label", void 0),
            __decorate([p(cc.Node)], t.prototype, "player_node_view", void 0),
            __decorate([p(cc.Label)], t.prototype, "tip_label", void 0),
            __decorate([u], t)
        );
    })(n.default);
o.default = m;
